<?php
	require_once "Zend/Application.php";
	
	require_once "MDB2.php";
	require_once "../config/constant.php";
	require_once "myfunc.php";
	
	// Define path to application directory
	defined("APPLICATION_PATH") || define("APPLICATION_PATH", realpath(dirname(__FILE__) . "/../application"));
	
	// Define application environment
	defined("APPLICATION_ENV") || define("APPLICATION_ENV", (getenv("APPLICATION_ENV") ? getenv("APPLICATION_ENV") : "production"));
	
	// Create application, bootstrap, and run
	$application = new Zend_Application(APPLICATION_ENV, APPLICATION_PATH . "/configs/application.ini");
	$controller = Zend_Controller_Front::getInstance();
	$controller->throwExceptions(true); 
	$controller->setParam("noViewRenderer", true);
	
	// Init database connection
	$dbOptions = array("portability" => MDB2_PORTABILITY_NONE);
	
	$dbWriter = &MDB2::factory(DB_DNS_WRITER, $dbOptions);
	$dbWriter->loadModule("Extended");
	$dbWriter->setFetchMode(MDB2_FETCHMODE_ASSOC);
	
	$dbReader = &MDB2::factory(DB_DNS_READER, $dbOptions);
	$dbReader->loadModule("Extended");
	$dbReader->setFetchMode(MDB2_FETCHMODE_ASSOC);
	
	// Init email connection
	$smtpConfig = array("auth" => "login", "username" => MAIL_USERNAME, "password" => MAIL_PASSWORD);
	$smtp = new Zend_Mail_Transport_Smtp(MAIL_HOSTNAME, $smtpConfig);
	
	$resource = $application->getBootstrap()->getPluginResource("db");
	$db = $resource->getDbAdapter();
	Zend_Registry::set("DB", $db);
	
	$smarty = new STE_Smarty(APPLICATION_PATH . "/../templates");
	Zend_Registry::set("SMARTY", $smarty);
	//$acc=counter1();
	//$user_online = counter();
	// Setup registry and session
	Zend_Registry::set("DBWRITER", $dbWriter);
	Zend_Registry::set("DBREADER", $dbReader);
	Zend_Registry::set("SMTP", $smtp);
	//Zend_Registry::set("COUNTER_ACC", $acc);
	//Zend_Registry::set("COUNTER_ONLINE", $user_online);
	Zend_Session::start();
	
	$alphaSession = new Zend_Session_Namespace("STE_WEBSITE_ALPHA");
	if ((!isset($alphaSession->isVisit)) || ($alphaSession->isVisit == 0))
	{
		if ($_SERVER["REQUEST_URI"] != "/welcome")
		{
			$alphaSession->referer = $_SERVER["REQUEST_URI"];
			header("Location: /welcome");
		}
	}
	
	$application->bootstrap()->run();
?>